home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / tables / table.frm < prev    next >
Text File  |  1995-09-06  |  7KB  |  220 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00FFFF00&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "MarkUps R Us"
  6.    ClientHeight    =   2880
  7.    ClientLeft      =   1605
  8.    ClientTop       =   1740
  9.    ClientWidth     =   6225
  10.    Height          =   3285
  11.    Left            =   1545
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   2880
  17.    ScaleWidth      =   6225
  18.    Top             =   1395
  19.    Width           =   6345
  20.    Begin VScrollBar VScroll1 
  21.       Height          =   2055
  22.       Left            =   5640
  23.       TabIndex        =   4
  24.       Top             =   480
  25.       Width           =   255
  26.    End
  27.    Begin Label Label5 
  28.       Alignment       =   1  'Right Justify
  29.       BorderStyle     =   1  'Fixed Single
  30.       Caption         =   "InStock"
  31.       Height          =   2055
  32.       Left            =   4680
  33.       TabIndex        =   10
  34.       Top             =   480
  35.       Width           =   975
  36.    End
  37.    Begin Label Label4 
  38.       Alignment       =   1  'Right Justify
  39.       BackColor       =   &H00FFFFFF&
  40.       BorderStyle     =   1  'Fixed Single
  41.       Caption         =   "Price"
  42.       ForeColor       =   &H00FF0000&
  43.       Height          =   2055
  44.       Left            =   3720
  45.       TabIndex        =   3
  46.       Top             =   480
  47.       Width           =   975
  48.    End
  49.    Begin Label Label3 
  50.       Alignment       =   1  'Right Justify
  51.       BorderStyle     =   1  'Fixed Single
  52.       Caption         =   "MarkUp"
  53.       Height          =   2055
  54.       Left            =   2760
  55.       TabIndex        =   2
  56.       Top             =   480
  57.       Width           =   975
  58.    End
  59.    Begin Label Label2 
  60.       Alignment       =   1  'Right Justify
  61.       BorderStyle     =   1  'Fixed Single
  62.       Caption         =   "Cost"
  63.       Height          =   2055
  64.       Left            =   1800
  65.       TabIndex        =   1
  66.       Top             =   480
  67.       Width           =   975
  68.    End
  69.    Begin Label Label1 
  70.       BorderStyle     =   1  'Fixed Single
  71.       Caption         =   "ProdName"
  72.       Height          =   2055
  73.       Left            =   360
  74.       TabIndex        =   0
  75.       Top             =   480
  76.       Width           =   1455
  77.    End
  78.    Begin Label Label10 
  79.       Alignment       =   2  'Center
  80.       BackColor       =   &H00C0C0C0&
  81.       BorderStyle     =   1  'Fixed Single
  82.       Caption         =   "In Stock"
  83.       Height          =   255
  84.       Left            =   4680
  85.       TabIndex        =   9
  86.       Top             =   240
  87.       Width           =   975
  88.    End
  89.    Begin Label Label9 
  90.       Alignment       =   2  'Center
  91.       BackColor       =   &H00C0C0C0&
  92.       BorderStyle     =   1  'Fixed Single
  93.       Caption         =   "Price"
  94.       Height          =   255
  95.       Left            =   3720
  96.       TabIndex        =   8
  97.       Top             =   240
  98.       Width           =   975
  99.    End
  100.    Begin Label Label8 
  101.       Alignment       =   2  'Center
  102.       BackColor       =   &H00C0C0C0&
  103.       BorderStyle     =   1  'Fixed Single
  104.       Caption         =   "MarkUp"
  105.       Height          =   255
  106.       Left            =   2760
  107.       TabIndex        =   7
  108.       Top             =   240
  109.       Width           =   975
  110.    End
  111.    Begin Label Label7 
  112.       Alignment       =   2  'Center
  113.       BackColor       =   &H00C0C0C0&
  114.       BorderStyle     =   1  'Fixed Single
  115.       Caption         =   "Cost"
  116.       Height          =   255
  117.       Left            =   1800
  118.       TabIndex        =   6
  119.       Top             =   240
  120.       Width           =   975
  121.    End
  122.    Begin Label Label6 
  123.       BackColor       =   &H00C0C0C0&
  124.       BorderStyle     =   1  'Fixed Single
  125.       Caption         =   "Product Name"
  126.       Height          =   255
  127.       Left            =   360
  128.       TabIndex        =   5
  129.       Top             =   240
  130.       Width           =   1455
  131.    End
  132. End
  133.     
  134.  
  135. '---------------------------------------------------------
  136. ' This is the routine that creates the Captions for each
  137. ' Label Control. The captions consist of two strings for
  138. ' each line of the Label Control. The first string is the
  139. ' value that is to be displayed on a Label line. The second
  140. ' string is the End Of Line string (EOL$) which consists
  141. ' of several blank spaces to center the text in the
  142. ' middle of the label followed by a Carriage Return
  143. ' Chr$(13) and a LineFeed Chr$(10).
  144. '
  145. ' This routine is called by the Form_Load routine and the
  146. ' VScroll1_Change routine.
  147. '---------------------------------------------------------
  148. '
  149. Sub DisplayItems ()
  150.  
  151.     '==> The End Of Line string.
  152.     EOL$ = "    " + Chr$(13) + Chr$(10)
  153.     
  154.     '==> VScroll1.Value is the index to the Item that
  155.     '    is displayed as the first item in the table.
  156.     Ndx% = VScroll1.Value
  157.     
  158.     '==> Build the strings for the first Item in the table.
  159.     Label1.Caption = Item(Ndx%).ProdName
  160.     Label2.Caption = Format$(Item(Ndx%).Cost, "0.00")
  161.     Label3.Caption = Format$(Item(Ndx%).MarkUp, "0.0000")
  162.     Label4.Caption = Format$(Item(Ndx%).Price, "0.00")
  163.     Label5.Caption = Format$(Item(Ndx%).InStock, "##,##0")
  164.  
  165.     '==> Add the rest of the Items in the table to the
  166.     '    initial strings.
  167.     For I% = Ndx% + 1 To Ndx% + TableLen - 1
  168.         Label1.Caption = Label1.Caption + EOL$ + Item(I%).ProdName
  169.         Label2.Caption = Label2.Caption + EOL$ + Format$(Item(I%).Cost, "0.00")
  170.         Label3.Caption = Label3.Caption + EOL$ + Format$(Item(I%).MarkUp, "0.0000")
  171.         Label4.Caption = Label4.Caption + EOL$ + Format$(Item(I%).Price, "0.00")
  172.         Label5.Caption = Label5.Caption + EOL$ + Format$(Item(I%).InStock, "##,##0")
  173.     Next I%
  174.  
  175.     '==> Append blanks to the last Item to keep it aligned.
  176.     Label2.Caption = Label2.Caption + "    "
  177.     Label3.Caption = Label3.Caption + "    "
  178.     Label4.Caption = Label4.Caption + "    "
  179.     Label5.Caption = Label5.Caption + "    "
  180.  
  181. End Sub
  182.  
  183. Sub Form_Load ()
  184.     
  185.     '==> Set the random number generator seed.
  186.     Randomize
  187.     
  188.     '==> Generate random sample data.
  189.     For I% = 1 To MaxItems
  190.         Item(I%).ProdName = String$(6, 33 + I%) '=> Dummy Product name.
  191.         Item(I%).Cost = Int(Rnd * 70 + 1)       '=> Cost of $1 to $70.
  192.         Item(I%).MarkUp = Rnd                   '=> Markup as decimal.
  193.         Item(I%).Price = Item(I%).Cost * (1 + Item(I%).MarkUp)
  194.         Item(I%).InStock = Rnd * 1500
  195.     Next I%
  196.  
  197.     '==> Set the parameters for the vertical scroll bar.
  198.     VScroll1.Min = 1
  199.     VScroll1.Max = MaxItems - TableLen   '=> So we don't overrun the end of the Item array.
  200.     VScroll1.SmallChange = 1
  201.     VScroll1.LargeChange = TableLen - 1  '=> We want a 1 item overlap between pages.
  202.     VScroll1.Value = VScroll1.Min
  203.  
  204.  
  205.     '==> Display the Items. Note that the top
  206.     '    item in the table is always Item(VScroll1.Value).
  207.     Call DisplayItems
  208.  
  209.  
  210. End Sub
  211.  
  212. Sub VScroll1_Change ()
  213.  
  214.     '==> Display the set of Items beginning with the
  215.     '    current VScroll1.Value.
  216.     Call DisplayItems
  217.  
  218. End Sub
  219.  
  220.